﻿(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['jquery', 'use!underscore', 'use!backbone', 'libs/moment/moment.min'], function($, _, Backbone) {
    var Photo;
    return Photo = (function(_super) {

      __extends(Photo, _super);

      function Photo(attributes, options) {
        Backbone.Model.apply(this, arguments);
      }

      Photo.prototype.initialize = function() {
        var _this = this;
        return this.on('change', function() {
          if (_this.hasChanged() && _this.previousAttributes()['created'].match(/\/Date\(-?\d+\)\//)) {
            if (typeof _this.get('cost') === 'string') {
              _this.set('cost', accounting.unformat(_this.get('cost'), ',').toFixed(2).replace('.', ','), {
                silent: true
              });
            }
            _this.url = '/Photo/Edit/';
            return _this.save(_this.changedAttributes());
          }
        });
      };

      Photo.prototype.defaults = {
        name: 't',
        filename: 'blank.png',
        caption: 't',
        photographer: 't',
        licence: 't',
        cost: 0.0,
        created: '/Date(' + moment().valueOf() + ')/',
        type: ''
      };

      Photo.prototype.validate = function(attrs) {
        var error;
        error = null;
        _.each(attrs, function(val) {
          if (val === '') {
            return error = 'Please compleate all fields';
          }
        });
        if (error) {
          return error;
        }
      };

      return Photo;

    })(Backbone.Model);
  });

}).call(this);
